/**
 * 
 */
package org.log4jconfig.xml.editor.quickfix;

import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
import org.eclipse.jface.text.quickassist.IQuickAssistProcessor;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.log4jconfig.xml.editor.utils.StructuredDocumentRegionUtils;

/**
 * @author A207119
 *
 */
@SuppressWarnings("restriction")
public class AnyDeprecatedElementQuickAssistProcessor implements
		IQuickAssistProcessor {

	/* (non-Javadoc)
	 * @see org.eclipse.jface.text.quickassist.IQuickAssistProcessor#canAssist(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext)
	 */
	public boolean canAssist(IQuickAssistInvocationContext invocationContext) {
		return true;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.text.quickassist.IQuickAssistProcessor#canFix(org.eclipse.jface.text.source.Annotation)
	 */
	public boolean canFix(Annotation annotation) {
		return true;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.text.quickassist.IQuickAssistProcessor#computeQuickAssistProposals(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext)
	 */
	public ICompletionProposal[] computeQuickAssistProposals(
			IQuickAssistInvocationContext invocationContext) {
		int offset = invocationContext.getOffset();
		ISourceViewer sourceViewer = invocationContext.getSourceViewer();
		IStructuredDocument document = (IStructuredDocument)sourceViewer.getDocument();
		IStructuredDocumentRegion[] regions = document.getStructuredDocumentRegions(offset, 0);
		String tagName = StructuredDocumentRegionUtils.extractTagName(regions[0]);
		if("category".equals(tagName) || "priority".equals(tagName)) {
			return new ICompletionProposal[] {new AllDeprecatedElementsReplaceQuickFix()};
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.text.quickassist.IQuickAssistProcessor#getErrorMessage()
	 */
	public String getErrorMessage() {
		return "Error message";
	}

}
